package com.william.jdbcplus.core.toolkit;

import java.security.SecureRandom;
import java.util.UUID;

public class UuidUtil {

    private static SecureRandom random = new SecureRandom();

    /**
     * 封装JDK自带的UUID, 通过Random数字生成, 中间有-分割.
     */
    public static String getUuid() {
        return UUID.randomUUID().toString();
    }

    public static String get32UUID() {
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }

    public static String get32UpperUUID() {
        String uuid = get32UUID();
        return uuid.toUpperCase();
    }

    /**
     * 使用SecureRandom随机生成Long.
     */
    public static long randomLong() {
        //wangd 当random.nextLong()为Long.MIN_VALUE时取绝对值还是Long.MIN_VALUE待处理
        return Math.abs(random.nextLong());
    }

    public static void main(String[] args) {
        System.out.println(get32UUID());
        System.out.println(get32UpperUUID());
        System.out.println(randomLong());
    }

}
